/**
 * 
 */

package com.chengyu.eyc.queue;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.ExchangeBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author kevin
 *
 */

@Configuration
public class RabbitMQConfig {

    // 队列
    // 交换机名称
    public static final String ORDER_TOPIC_EXCHANGE = "order_topic_exchange";
    
    public static final String MESSAGE_TOPIC_EXCHANGE = "message_topic_exchange";

    // 队列名称
    public static final String ORDER_QUEUE = "order_queue";
    // 队列名称
    public static final String MESSAGE_QUEUE = "message_queue";

    // 绑定队列和交换机
    @Bean
    public Binding itemQueueExchange(@Qualifier("orderQueue") Queue queue, @Qualifier("orderTopicExchange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("order.#").noargs();
    }
    
    @Bean("messageQueue")
    public Queue messageQueue() {
        return QueueBuilder.durable(MESSAGE_QUEUE).build();
    }


    // 绑定队列和交换机
    @Bean
    public Binding messageQueueExchange(@Qualifier("messageQueue") Queue queue, @Qualifier("messageTopicExchange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("message.#").noargs();
    }
    
    // 声明交换机
    @Bean("messageTopicExchange")
    public Exchange messageTopicExchange() {
        return ExchangeBuilder.topicExchange(MESSAGE_TOPIC_EXCHANGE).durable(true).build();
    }
 
    // 声明队列
    @Bean("orderQueue")
    public Queue orderQueue() {
        return QueueBuilder.durable(ORDER_QUEUE).build();
    }
    
    // 声明交换机
    @Bean("orderTopicExchange")
    public Exchange topicExchange() {
        return ExchangeBuilder.topicExchange(ORDER_TOPIC_EXCHANGE).durable(true).build();
    }

   

}
